"""author: wangxin
   data: 2021/12/8
   project: cjh.py
"""

# 正数在前负数在后 正数从小到大 负数从大到小
lst1 = [7, -8, 5, 4, 0, -2, -5]
print(sorted(lst1, key=lambda x: x * -1000000000 if x <= 0 else x))

# 小写<大写<奇数<偶数
s = 'asdf234GDSdsf23'


def func1(s):
    for i in s:
        if i.isdigit():
            if int(i) % 2 == 0:
                return (True, True, i)
            else:
                return (True, False, i)
        elif i.isupper():
            return (False, True, i)
        elif i.islower():
            return (False, False, i)


print(''.join(sorted(s, key=func1)))

# 利用map批量检测用户名是否符合规范
# 只能包含数字、字母、下划线、不以数字开头，长度在6-18之间
import re


def func2(username):
    if re.findall("^[A-Za-z_][A-Za-z\d\_]{5,17}", username):
        return f"{username}符合规范"
    else:
        return f"{username}不符合规范"


username = ['wadwadWDWFW', 'sASSWdwawd', '1dedwedwdqdqdq', 'wwwww']
print(list(map(func2, username)))


# filter 把合法的用户名显示出来
def func3(username):
    if re.findall("^[A-Za-z_][A-Za-z\d\_]{5,17}", username):
        return 1
    else:
        return 0


print(list(filter(func3, username)))

# 匿名函数+reduce实现n的阶乘

from functools import reduce

n = int(input("请输入一个整数："))
print(reduce(lambda x, y: x * y, range(1, n + 1)))


# filter 函数找出[1-100]能被3 整除的数

def func4(x):
    if x % 3 == 0:
        return 1


print(list(filter(func4, range(1, 101))))

# map函数求list[1-10]各项的平方
print(list(map(lambda x: x * x, range(1, 11))))
